oo::class create Lineend {
    superclass Plugin
    variable RenamedPadWidget

    constructor {renamedPadWidget {background #FFFFFF}} {
        set RenamedPadWidget $renamedPadWidget
        $RenamedPadWidget tag configure Lineend -background $background
    }

    method clearLineend {args} {
        set i 0
        set ids [$RenamedPadWidget tag ranges Lineend]
        while {$i < [llength $ids]} {
            set f [lindex $ids $i]
            set t [lindex $ids $i+1]
            # puts "--$f -> $t--"
            $RenamedPadWidget tag remove Lineend $f $t
            $RenamedPadWidget delete $f $t
            incr i 2
        }
    }

    method appendLineend {args} {
        if [$RenamedPadWidget compare insert == {insert lineend}] {
            set index [$RenamedPadWidget index insert]
            $RenamedPadWidget insert $index { } Lineend
            $RenamedPadWidget mark set insert $index
        }
    }

    method appendLineendAfterReplace {from to content args} {
        my clearLineend
        my appendLineend
    }

    method getPluginEvents {} {
        return {
            {beforeMarkSetInsert clearLineend}
            {afterMarkSetInsert appendLineend}

            {beforeDelete clearLineend}
            {afterDelete appendLineend}
            {afterReplace appendLineendAfterReplace}
        }
    }
}